<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>联币ICO</title>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="__ROOT__/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="__ROOT__/css/bootstrap-theme.css">
    <link rel="stylesheet" type="text/css" href="__ROOT__/css/common.css">
</head>
<body>
<div class="wrap container-fluid">
    <form action="/index/index/upSupport" class="reg-form" method="post" accept-charset="utf-8">

        <div class="form-group">
            <h1>BTC支持</h1>
        </div>
        <label for="BTC" style="font-size: 18px">当前可用:<span class="text-success">{$btc_num}</span>BTC</label>
        <div class="form-group">
            <input type="text" name="number" class="form-control" id="BTC" oninput="check_number(this);" placeholder="请输入支持数量">
            <!--<div class="error">-->
            <!--错误信息提示-->
            <!--</div>-->
        </div>
        <!-- 用户手机号 -->
        <input type="hidden" name="mobile" value="{$mobile}">
        <div class="form-group valume">
            <input type="text" name="code" class="form-control" placeholder="请输入验证码">
            <button type="button" class="btn btn-success" id='getcode' disabled="" value="1">获取验证码</button>
        </div>
        <input type="hidden" name="msg_id">
        <div class="form-group">
            <button type="submit" class="btn btn-success">支持</button>
        </div>
    </form>
</div>
<input type="hidden" class="error" name="" value="{$error ?: ''}">
<script type="text/javascript" src='__ROOT__/js/jquery.js'></script>
<script type="text/javascript" src='__ROOT__/layer/layer.js'></script>
<script type="text/javascript" src='__ROOT__/js/getCode.js'></script>
<script type="text/javascript">
    //数量验证
    function check_number(index){
        var num = $(index).val();
        var l = num.length-1;
        var max_num = Number("{$btc_num}");
        var reg = /^\d\.?\d{0,4}$/;
        if(!reg.test(num)){
            $(index).val(num.slice(0,l));
            layer.msg('请输入正确格式！最大支持五位数');
        }else if(num>max_num){
            layer.msg('不能超过当前可用数!');
            $(index).val(num.slice(0,l));
        }else{
            $('#getcode').attr('disabled',false);
        }
    }
    $(function () {
        $('form').submit(function () {
            var input = $('input[type="text"]');
            for (var i = 0; i < input.length; i++) {
                if (!input.eq(i).val()) {
                    layer.msg('请填写支持数量或验证码！')
                    return false;
                }
            }
            var num = $('input[name="number"]').val();
            if (!/^\d\.?\d{0,5}$/.test(num)) {
                layer.msg('请填写数量,最大支持位数5位！')
                return false;
            }
            $.post("{:url('upSupport')}",$('form').serialize(),function(e){
                if(e.code==1){
                    layer.msg(e.msg,{icon:1,time:2000});
                    setTimeout("window.location.href='"+e.url+"'",2000);
                }else{
                    layer.msg(e.msg,{icon:2,time:2000});
                }
            })
            return false;
        });
        Code.getcode($, '#getcode', '/index/index/sendPhoneCode', function (msg) {
            $('input[name="msg_id"]').val(msg.msg_id)
            Code.timeStart($, 60, '#getcode', Code.isClicked)
        });
        if ($('.error').val()) {
            layer.alert($('.error').val(), {icon: 5})
        }
    })


</script>
</body>
</html>